package com.example.expandview;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * created by liangkun on ${DATA}
 * Describe:
 */

public class SimpleAdapter extends RecyclerView.Adapter<SimpleAdapter.ViewHolder> {
    private Context context;
    // 列表展开标识
    int opened = -1;
    // 为列表提供数据的数据集合
    private List<String> contacts;


    /**
     * 构造方法
     *
     * @param context
     */
    public SimpleAdapter(Context context, List<String> array) {
        this.context = context;
        this.contacts = array;

    }

    /**
     * 增加数据
     */
    public void addData(int position) {
        for (int i = 0; i < 10; i++) {
            contacts.add(position, "addkun" + i);
            notifyItemInserted(position);//注意这里
        }

    }

    @NonNull
    @Override
    public SimpleAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.left_child_month, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int postion) {

        String contact = contacts.get(postion);
        viewHolder.tvView.setText(contact);

    }


    @Override
    public int getItemCount() {
        return contacts.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        protected TextView tvView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvView = itemView.findViewById(R.id.tv_item);
        }
    }
}
